<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>UDT Reference</title>
</head>

<body>

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table8" bgcolor="#99CCFF" bordercolor="#99CCFF">
  <tr>
    <td width="100%"><font face="Verdana" size="2"><i>&nbsp;UDT </i></font><i>
	<font face="Verdana" size="2">Tutorial</font></i></td>
  </tr>
</table>
<h1><font face="Verdana" size="4">Add New Congestion Control Algorithm</font></h1>
<p><font face="Verdana" size="2"><b><font color="#FF0000">STOP</font></b>: Make sure
that you have uncommented the -DCUSTOM_CC compiler option in ./src/Makefile.
Otherwise your control algorithm will NOT be used.</font></p>
<p><font face="Verdana" size="2">You can add your own congestion control 
algorithm into UDT. It is as simple as to define several callback functions that 
will be triggered on certain events, e.g, when an ACK is received.</font></p>
<p><font face="Verdana" size="2">All the congestion control callback functions 
are collected in a C++ class <b><a href="ccc.htm">CCC</a></b>. You have to inherit this class to define your 
own congestion control algorithm. That is, UDT/CCC uses an object-oriented 
design. CCC in defined in ccc.h, which you have to include in your files in 
order to enable this feature.</font></p>
<p><font face="Verdana" size="2">The CCC class contains two control variables: 
<a href="ccc.htm#11">m_dPktSndPeriod</a>, and <a href="ccc.htm#12">m_dCWndSize</a>. 
<a href="ccc.htm#11">m_dPktSndPeriod</a> is a double float number 
representing the packet sending period (as to be used in rate control), in 
microseconds. <a href="ccc.htm#12">m_dCWndSize</a> is a double float number representing the size of the 
congestion window (cwnd), in number of packets. The congestion control algorithm 
will need to update at least one of them. For example, for pure window based 
approach, <a href="ccc.htm#11">m_dPktSndPeriod</a> should always be zero.</font></p>
<p><font face="Verdana" size="2">The fast way to learn CCC is to use the 
examples in ./app/cc.h. The file cc.h also includes many more advanced control 
mechanisms that your control classes can be derived from. For example, if you 
are designing a new TCP variant, you can implement the new control class 
directly from CTCP.</font></p>
<p><font face="Verdana" size="2">Here we demonstrate the usage of UDT/CCC by 
writing a reliable UDP blast control mechanism.</font></p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table9" bgcolor="#C0C0C0" bordercolor="#C0C0C0">
  <tr>
    <td width="100%">
    <p style="margin-top: 0; margin-bottom: 0">
	<font face="Courier New" size="1">class CUDPBlast: public CCC<br>
	{<br>
	public:<br>
&nbsp;&nbsp; CUDPBlast() {m_dCWndSize = 83333.0;}<br>
	<br>
	public:<br>
&nbsp;&nbsp; void setRate(int mbps)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_dPktSndPeriod = (m_iSMSS * 8.0) / mbps;<br>
&nbsp;&nbsp; }<br>
	<br>
	protected:<br>
&nbsp;&nbsp; static const int m_iSMSS = 1500;<br>
	};</font></p>
    </td>
  </tr>
</table>
<p><font face="Verdana" size="2">In this example, <i>CUDPBlast</i> inherits from 
the base class <b><a href="ccc.htm">CCC</a></b>. In the constructor, it sets the 
congestion window size to a large value so that it will not affect the packet 
sending. (This is pure rate based method to blast UDP packets.) The method <i>
SetRate()</i> can be used to set a fixed packet sending rate at any time.</font></p>
<p><font face="Verdana" size="2">The application can use <b><a href="opt.htm">
setsockopt/getsockopt</a></b> to assign this control class to a UDT instance, 
and/or set its parameters.</font></p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table10" bgcolor="#C0C0C0" bordercolor="#C0C0C0">
  <tr>
    <td width="100%">
    <p style="margin-top: 0; margin-bottom: 0">
	<font face="Courier New" size="1">UDT::setsockopt(usock, 0, UDT_CC, new 
	CCCFactory&lt;CUDPBlast&gt;, sizeof(CCCFactory&lt;CUDPBlast&gt;));</font></p>
    </td>
  </tr>
</table>
<p><font face="Verdana" size="2">The above code assigns the <i>CUDPBlast</i> 
control algorthm to a UDT socket <i>usock</i>. Note that <i>CCCFactory&lt;CUDPBlast&gt;</i> 
is using the Abstract Factory design pattern.</font></p>
<p><font face="Verdana" size="2">To set a specific data sending rate, the 
application needs to obtain a handle to the concrete CCC class instance used by 
the UDT socket <i>usock</i>.</font></p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table11" bgcolor="#C0C0C0" bordercolor="#C0C0C0">
  <tr>
    <td width="100%">
    <p style="margin-top: 0; margin-bottom: 0">
	<font face="Courier New" size="1">CUDPBlast* cchandle = NULL;<br>
	int temp;<br>
	UDT::getsockopt(usock, 0, UDT_CC, &amp;cchandle, &amp;temp);</font></p>
    </td>
  </tr>
</table>
<p><font face="Verdana" size="2">The application can then call the method of <i>
setRate() </i>to set a 500Mbps data rate.</font></p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="table12" bgcolor="#C0C0C0" bordercolor="#C0C0C0">
  <tr>
    <td width="100%">
    <p style="margin-top: 0; margin-bottom: 0">
	<font face="Courier New" size="1">if (NULL != cchandle)<br>
&nbsp;&nbsp; cchandle-&gt;setRate(500);</font></p>
    </td>
  </tr>
</table>
<p><font face="Verdana" size="2">The UDT/CCC can be used to implement most 
control mechanims, including but not limited to rate-based approaches, TCP 
variants (e.g., TCP, Scalable, HighSpeed, BiC, Vegas, FAST), and group-based 
approaches (e.g., GTP, CM).</font></p>
<H4><font face="Verdana" size="2">Note</font></H4>
<p><font face="Verdana" size="2">Do NOT call regular UDT API inside CCC or its 
derived classes. Unknown error could happen.</font></p>
<p><font face="Verdana" size="2">CCCFactory&lt;...&gt; is a C++ template class. You do 
not need to derive any classes from it.</font></p>
<p><font face="Verdana" size="2">UDT will not release the CCCFactory&lt;...&gt; 
instance. The application should release it, at anywhere after the setsockopt() 
call.</font></p>
<H4><font face="Verdana" size="2">See Also</font></H4>
<P>
<b><font face="Verdana" size="2"><a href="ccc.htm">Congestion Control Class</a></font></b></P>

</body>

</html>
